package com.dhcc.DRGsHosp.facade.impl.assembler;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.dhcc.DRGsHosp.core.domain.ClinicGroup;
import com.dhcc.DRGsHosp.facade.dto.ClinicGroupDTO;
import com.dhcc.DRGsHosp.infra.util.StringUtils;

public class ClinicGroupAssembler {
	
	public static ClinicGroupDTO  toDTO(ClinicGroup  clinicGroup){
		if (clinicGroup == null) {
			return null;
		}
    	ClinicGroupDTO result  = new ClinicGroupDTO();
			result.setId (clinicGroup.getId());
	    	result.setGroupName (clinicGroup.getGroupName());
	    	result.setParDepCode (clinicGroup.getParDepCode());
	    	result.setParDepName(clinicGroup.getDepName());
	    	// 关联病区编码为空时，病区名称为空
	    	if(StringUtils.isEmpty(clinicGroup.getParWardCode())){
	    		result.setParWardDesc("");
	    	} else {
	    		result.setParWardDesc(clinicGroup.getWardDesc());
	    	}
	    	result.setGroupOrder(clinicGroup.getGroupOrder());
	    	result.setGroupCode(clinicGroup.getGroupCode());
	    	result.setGroupType(clinicGroup.getGroupType());
	    	result.setParWardCode(clinicGroup.getParWardCode());
	    	result.setGroupActive(clinicGroup.getGroupActive());
	    	result.setParDepGroupCode(clinicGroup.getParDepGroupCode());
	    	result.setGroupTypeDesc(clinicGroup.getGroupTypeDesc());
     	    return result;
	 }
	
	public static List<ClinicGroupDTO>  toDTOs(Collection<ClinicGroup>  clinicGroups){
		if (clinicGroups == null) {
			return null;
		}
		List<ClinicGroupDTO> results = new ArrayList<ClinicGroupDTO>();
		for (ClinicGroup each : clinicGroups) {
			results.add(toDTO(each));
		}
		return results;
	}
	
	 public static ClinicGroup  toEntity(ClinicGroupDTO  clinicGroupDTO){
	 	if (clinicGroupDTO == null) {
			return null;
		}
	 	ClinicGroup result  = new ClinicGroup();
        result.setId (clinicGroupDTO.getId());
        result.setGroupName (clinicGroupDTO.getGroupName());
        result.setParDepCode (clinicGroupDTO.getParDepCode());
        result.setParWardCode (clinicGroupDTO.getParWardCode()!=null?clinicGroupDTO.getParWardCode():"null");
        result.setGroupOrder(clinicGroupDTO.getGroupOrder()!=null?clinicGroupDTO.getGroupOrder():"0");
        result.setGroupCode(clinicGroupDTO.getGroupCode());
        result.setGroupType(clinicGroupDTO.getGroupType());
        result.setGroupActive(clinicGroupDTO.getGroupActive());
        result.setParDepGroupCode(clinicGroupDTO.getParDepGroupCode());
        result.setGroupTypeDesc(clinicGroupDTO.getGroupTypeDesc());
 	  	return result;
	 }
	
	public static List<ClinicGroup> toEntities(Collection<ClinicGroupDTO> clinicGroupDTOs) {
		if (clinicGroupDTOs == null) {
			return null;
		}
		
		List<ClinicGroup> results = new ArrayList<ClinicGroup>();
		for (ClinicGroupDTO each : clinicGroupDTOs) {
			results.add(toEntity(each));
		}
		return results;
	}
}
